import React, { Component } from 'react'
import './index.css'

export default class footer extends Component {

    handleCkeckAll = (event)=>{
        this.props.checkalltodo(event.target.checked)
    }

    handleClearAll = ()=>{
        this.props.clearAllTodoDone()
    }
    render() {
        const {todos} = this.props
        //已完成的个数
        const doneCount = todos.reduce((pre,todo)=>{
            return pre + (todo.done ? 1:0)
        },0)
        //总数
        const allCount = todos.length

        return (
            <div className="todo-footer">
                <label>
                    <input type="checkbox" onChange={this.handleCkeckAll} checked={doneCount === allCount&&allCount!==0?true:false} />
                </label>
                <span>
                    <span>已完成{doneCount}</span> / 全部{allCount}
                </span>
                <button onClick = {this.handleClearAll} className="btn btn-danger">清除已完成</button>
            </div>
        )
    }
}
